import React from 'react'
import { Redirect } from 'react-router-dom'
import { connect } from 'react-redux'
import axios from 'axios'
import { login, getUserData } from './Auth.redux'
@connect(state => ({ auth: state.auth }), { login, getUserData })
class Auth extends React.Component{
    componentDidMount(){
        this.props.getUserData()
    }
    render(){
        return this.props.auth.isAuth ? (
            <Redirect to="/dashboard"/>
        ) : (
            <>
            <h1>需要登录才能访问</h1>
            <button onClick={this.props.login}>登录</button>
            </>
        )
    }
}

export default Auth